#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <stdlib.h>
struct ListNode 
{
    int val;
    struct ListNode* next;
};
struct ListNode* detectCycle(struct ListNode* head)
{
    struct ListNode* fast = head, * slow = head;
    do
    {
        if (fast && fast->next)
        {
            fast = fast->next->next;
            slow = slow->next; 
        }
        else
        {
            return NULL;
        }
    } while (fast != slow);
    struct ListNode* meet = slow;
    while (meet != head)
    {
        meet = meet->next;
        head = head->next;
    }
    return meet;
}
struct ListNode* SLTBuyNode(int x)
{
    struct ListNode* listnode = (struct ListNode*)malloc(sizeof(struct ListNode));
    if (listnode == NULL)
    {
        perror("malloc fail!");
        exit(1);
    }
    listnode->val = x;
    listnode->next = NULL;
    return listnode;
}
int main()
{
    struct ListNode* listnode = SLTBuyNode(1);
    detectCycle(listnode);
    return 0;
}